
package com.example.demo.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class TextUtils {
    private static Log logger = LogFactory.getLog(TextUtils.class);

    private TextUtils() { /* cannot be instantiated */
    }

    /**
     * Returns true if the string is null or 0-length.
     * 
     * @param str the string to be examined
     * @return true if str is null or zero length
     */
    public static boolean isEmpty(String str) {
        if (str == null || str.length() == 0 || "null".equals(str))
            return true;
        else
            return false;
    }

    public static boolean isPhoneNum(String phoneNum) {
        if (phoneNum == null) {
            return false;
        }
        phoneNum = phoneNum.trim();
        if (phoneNum.length() == 11) {
            return true;
        } else {
            return false;
        }

    }

    /**
     * 字符串转化为unicode
     * 
     * @param gbString
     * @return
     */
    public static String encodeUnicode(final String gbString) {
        char[] utfBytes = gbString.toCharArray();
        String unicodeBytes = "";
        for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {
            String hexB = Integer.toHexString(utfBytes[byteIndex]);
            if (hexB.length() <= 2) {
                hexB = "00" + hexB;
            }
            // unicodeBytes = unicodeBytes + "\\u" + hexB;
            unicodeBytes = unicodeBytes + hexB;
        }
        logger.info("字符串转化为unicode=" + unicodeBytes);
        // System.out.println(unicodeBytes);
        return unicodeBytes;
    }

    // unicode转化汉字
    public static StringBuffer decodeUnicode(String utfStr) {
        final StringBuffer buffer = new StringBuffer();
        String charStr = "";
        String operStr = utfStr;
        for (int i = 0; i < utfStr.length(); i = +4) {
            charStr = operStr.substring(0, 4);
            operStr = operStr.substring(4, operStr.length());
            char letter = (char) Integer.parseInt(charStr, 16);
            buffer.append(new Character(letter).toString());
        }
        logger.info("unicode转化汉字=" + buffer);
        return buffer;
    }

    // public static void main(String[] args) {
    // System.out.println(isPhoneNum("13572464208"));
    // }

    public static void main(String[] args) {
//        Date _Data = new Date(1467972096143l);
//        String[] _String = new String[] {
//                "fdss", "dsafsad"
//        };
//        String fuzhou = "福州市";
//        String fz2 = fuzhou.substring(0, fuzhou.length() - 1);
//        System.out.println("fz2=" + fz2);
//        System.out.println(DateUtils.getSimpleDateFormat().format(_Data));
//        String getString = "{\"respCode\":\"1000\",\"body\":{\"dataMap\":{\"phone_dhcpip\":\"192.168.0.19\",\"build_sdkint\":\"19\",\"phone_uid\":\"10288\",\"build_manufacturer\":\"vivo\",\"phone_gsmcid\":\"2339772\",\"phone_xdpi\":\"160.421\",\"build_fingerprint\":\"vivo/msm8916_32/msm8916_32:4.4.4/KTU84P/eng.compiler.20151211:user/dev-keys\",\"build_type\":\"user\",\"phone_androidid\":\"f378aa360cd2e3dd\",\"build_serial\":\"e04b682b\",\"phone_wifienabled\":\"true\",\"build_product\":\"msm8916_32\",\"phone_rssi\":\"-78\",\"phone_line1number\":\"+8618554176105\",\"phone_gprsip\":\"117.47.99.22\",\"phone_gsmlac\":\"40979\",\"build_codename\":\"REL\",\"build_user\":\"compiler\",\"phone_stationlatitude\":\"39.992\",\"phone_osarch\":\"armv7l\",\"phone_simoperator\":\"46001\",\"phone_height\":\"854\",\"phone_callstate\":\"0\",\"build_display\":\"KTU84P dev-keys\",\"phone_stationaltitude\":\"413.931\",\"build_release\":\"4.4.4\",\"phone_simserialnumber\":\"89860181034084286550\",\"phone_bluename\":\"vivo Y23L\",\"build_host\":\"compiler026\",\"phone_netinfotype\":\"1\",\"build_radio\":\"M8916AAAAANLYD1001501.1\",\"phone_linkspeed\":\"72\",\"phone_scaled\":\"1.5\",\"phone_isnetroaming\":\"false\",\"phone_networkid\":\"6\",\"phone_simoperatorname\":\"CHN-UNICOM\",\"phone_totalmem\":\"928340\",\"build_cpuabi2\":\"armeabi\",\"phone_subscriberid\":\"460015804144450\",\"phone_useragent\":\"Mozilla/5.0 (Linux; Android 4.4.4; vivo Y23L Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Ve\",\"phone_deviceid\":\"867699028086354\",\"phone_accounts\":\"[{\"type\":\"com.huawei.hwid\",\"name\":\"FepqlWwlChWGc\"},{\"type\":\"com.huawei.hwid\",\"name\":\"6CI8i\"},{\"type\":\"com.android.email\",\"name\":\"L6LT@163.com\"},{\"type\":\"com.android.email\",\"name\":\"E4TwxCzjxdlGzBl@3721.net\"},{\"type\":\"com.huawei.hwid\",\"name\":\"IGgZ9KI\"},{\"type\":\"com.sina.weibo\",\"name\":\"MVrGoGPVrFbh\"},{\"type\":\"com.sina.weibo\",\"name\":\"c2zJVImkiPDV8I\"},{\"type\":\"com.youku.phone\",\"name\":\"ojsmY4\"},{\"type\":\"com.android.email\",\"name\":\"S92WKB1LYcRN-@tom.cn\"},{\"type\":\"com.wandoujia\",\"name\":\"TmLlOpi2E5BHA\"},{\"type\":\"com.sina.weibo\",\"name\":\"kevhS-nwjwZsxDp\"}]\",\"phone_simcountryiso\":\"cn\",\"phone_hasicccard\":\"true\",\"build_device\":\"msm8916_32\",\"build_board\":\"msm8916\",\"build_incremental\":\"eng.compiler.20151211\",\"build_brand\":\"vivo\",\"build_cpuabi\":\"armeabi-v7a\",\"phone_netoperatorname\":\"中国联通\",\"phone_scantype\":\"cheat\",\"phone_bssid\":\"88:5b:dd:0d:2c:15\",\"build_model\":\"vivo Y23L\",\"phone_bluemac\":\"60:e3:27:2c:58:50\",\"phone_wifistate\":\"3\",\"phone_pid\":\"177\",\"phone_netoperator\":\"46001\",\"phone_dpi\":\"240\",\"phone_nettype\":\"3\",\"phone_ydpi\":\"159.497\",\"phone_stationlongitude\":\"116.331\",\"build_hardware\":\"qcom\",\"phone_netcountryiso\":\"cn\",\"phone_cpu\":\"Processor : ARMv7 Processor rev 0 (v7l)\nprocessor : 0\nmodel name : ARMv7 Processor rev 0 (v7l)\nBogoMIPS : 38.40\nFeatures : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt\nCPU implementer : 0x41\nCPU architecture: 7\nCPU variant : 0x0\nCPU part : 0xd03\nCPU revision : 0\nprocessor : 1\nmodel name : ARMv7 Processor rev 0 (v7l)\nBogoMIPS : 38.40\nFeatures : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt\nCPU implementer : 0x41\nCPU architecture: 7\nCPU variant : 0x0\nCPU part : 0xd03\nCPU revision : 0\nprocessor : 2\nmodel name : ARMv7 Processor rev 0 (v7l)\nBogoMIPS : 38.40\nFeatures : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt\nCPU implementer : 0x41\nCPU architecture: 7\nCPU variant : 0x0\nCPU part : 0xd03\nCPU revision : 0\nprocessor : 3\nmodel name : ARMv7 Processor rev 0 (v7l)\nBogoMIPS : 38.40\nFeatures : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt\nCPU implementer : 0x41\nCPU architecture: 7\nCPU variant : 0x0\nCPU part : 0xd03\nCPU revision : 0\nHardware : Qualcomm Technologies, Inc MSM8916\nRevision : 0000\nSerial  : 0000000000000000\",\"phone_kernal\":\"Linux version 3.10.28-svn3245 (compiler@compiler026) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Fri Dec\",\"build_bootloader\":\"unknown\",\"phone_wifiip\":\"192.168.0.19\",\"phone_density\":\"1.5\",\"phone_phonetype\":\"1\",\"phone_dns1ip\":\"220.107.143.42\",\"phone_ssid\":\"FAST_3AD4204\",\"phone_locType\":\"station\",\"phone_osversion\":\"3.10.28-svn3245\",\"phone_simstate\":\"5\",\"phone_deviceversion\":\"18\",\"phone_mac\":\"7c:e5:6b:82:31:04\",\"build_id\":\"KTU84P\",\"build_time\":\"1358425449404\",\"phone_width\":\"480\",\"phone_isnetinfoconnected\":\"true\"}}}";
//        System.out.println(getString.length());
//        StringTokenizer tokenizer = new StringTokenizer("cpd  dddd  dsfa");
//        int length = tokenizer.countTokens();
//        for (int i = 0; i < length; i++) {
//            System.out.println(tokenizer.nextToken());
//        }
    }
}
